const mysql = require('think-model-mysql');
const redisCache = require('think-cache-redis');
const fileCache = require('think-cache-file');
const {Console, File, DateFile} = require('think-logger3');
const path = require('path');
const isDev = think.env === 'development';
const socketio = require('think-websocket-socket.io');
const ws = require('think-websocket-ws');

/**
 * model adapter config
 * @type {Object}
 */
exports.model = {
    type: 'mysql',
    common: {
        logConnect: isDev,
        logSql: isDev,
        logger: msg => think.logger.info(msg)
    },
    mysql: {
        handle: mysql,
        database: 'hospital_cloud',
        prefix: '',
        encoding: 'utf8',
        host: '127.0.0.1',
        port: '3306',
        user: 'root',
        password: 'root',
        dateStrings: true
    }
};

/*exports.cache = {
	type: 'redis',
	common: {
		timeout: 24 * 3600 * 1000 // millisecond
	},
	redis: {
		handle: redisCache,
		port: 6379,
		host: '127.0.0.1',
		password: '',
		log_connect: true
	}
}*/
exports.cache = {
    type: 'file',
    common: {
        timeout: 24 * 60 * 60 * 1000 // millisecond
    },
    file: {
        handle: fileCache,
        cachePath: path.join(think.ROOT_PATH, 'runtime/cache'), // absoulte path is necessarily required
        pathDepth: 1,
        gcInterval: 24 * 60 * 60 * 1000 // gc interval
    }
};

/**
 * logger adapter config
 * @type {Object}
 */
exports.logger = {
    type: isDev ? 'console' : 'dateFile',
    console: {
        handle: Console
    },
    file: {
        handle: File,
	    level: 'ALL',
        backups: 10, // max chunk number
        absolute: true,
        maxLogSize: 50 * 1024, // 50M
        filename: path.join(think.ROOT_PATH, 'logs/app.log')
    },
    dateFile: {
        handle: DateFile,
        level: 'ALL',
        absolute: true,
        pattern: '-yyyy-MM-dd',
        alwaysIncludePattern: true,
        filename: path.join(think.ROOT_PATH, 'logs/app.log')
    }
};


exports.websocket = {
    type: 'socketio',
    common: {
        // common config
    },
    socketio: {
        handle: socketio,
	    pingInterval: 10000,
	    pingTimeout: 5000,
	    serveClient:false,
        allowOrigin: null,
        path: '/socket.io',
        adapter: null,
        messages: [{
	        namespace:'/',
            open: '/websocketio/open',
            message: '/websocketio/message',
	        close: '/websocketio/close'
        }]
    }
}

/*exports.websocket = {
	type: 'ws',
	common: {
		// common config
	},
	ws: {
		handle: ws,
		pingInterval: 10000,
	    pingTimeout: 5000,
	    serveClient:false,
		allowOrigin: null,
		path: '/',
		adapter: null,
		messages: [{
			open: '/websocket/open',
			message: '/websocket/message',
			close: '/websocket/close'
		}]
	}
}*/
